package com.vn.ld.btc.dao.entity;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.Date;

/**
 * The persistent class for the transactions database table.
 */
@Entity
@Table(name = "transactions")
@NamedQuery(name = "Transaction.findAll", query = "SELECT t FROM Transaction t")
public class Transaction implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "transaction_id", unique = true, nullable = false)
	private String transactionId;

	@Column(name = "fee_buy", precision = 10, scale = 6)
	private BigDecimal feeBuy;

	@Column(name = "fee_sell", precision = 10, scale = 6)
	private BigDecimal feeSell;

	@Column(name = "volume_buy", nullable = false, precision = 10, scale = 6)
	private BigDecimal volumeBuy;

	@Column(name = "volume_sell", nullable = false, precision = 10, scale = 6)
	private BigDecimal volumeSell;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "input_date")
	private Date inputDate;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_date")
	private Date updateDate;

	// bi-directional many-to-one association to Order
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "order_buy_id", nullable = false)
	private Order orderBuy;

	// bi-directional many-to-one association to Order
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "order_sell_id", nullable = false)
	private Order orderSell;

	public Transaction() {
	}

	public String getTransactionId() {
		return this.transactionId;
	}

	public void setTransactionId(String transactionId) {
		this.transactionId = transactionId;
	}

	public BigDecimal getFeeBuy() {
		return this.feeBuy;
	}

	public void setFeeBuy(BigDecimal feeBuy) {
		this.feeBuy = feeBuy;
	}

	public BigDecimal getFeeSell() {
		return this.feeSell;
	}

	public void setFeeSell(BigDecimal feeSell) {
		this.feeSell = feeSell;
	}

	public BigDecimal getVolumeBuy() {
		return this.volumeBuy;
	}

	public void setVolumeBuy(BigDecimal volumeBuy) {
		this.volumeBuy = volumeBuy;
	}

	public BigDecimal getVolumeSell() {
		return this.volumeSell;
	}

	public void setVolumeSell(BigDecimal volumeSell) {
		this.volumeSell = volumeSell;
	}

	public Date getInputDate() {
		return inputDate;
	}

	public void setInputDate(Date inputDate) {
		this.inputDate = inputDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public Order getOrderBuy() {
		return this.orderBuy;
	}

	public void setOrderBuy(Order orderBuy) {
		this.orderBuy = orderBuy;
	}

	public Order getOrderSell() {
		return this.orderSell;
	}

	public void setOrderSell(Order orderSell) {
		this.orderSell = orderSell;
	}

	@PrePersist
	private void prePersist() {
		this.inputDate = new Date();
		this.updateDate = new Date();
	}
	
	@PreUpdate
	private void preUpdate() {
		this.updateDate = new Date();
	}
}
